package il.ac.technion;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ReportController {
	@Autowired
	private TableDao tableDao;

	@RequestMapping(value = "report", method = RequestMethod.GET)
	public String report(Model m) {
		return reportTableList(m, tableDao.getObjects());
	}

	@RequestMapping(value = "report", method = RequestMethod.GET, params = { "tid" })
	public String report(Model m, int tid) {
		ArrayList<Table> tableList = new ArrayList<Table>();
		tableList.add(tableDao.getObjectById(tid));
		return reportTableList(m, tableList);
	}

	private String reportTableList(Model m, ArrayList<Table> tableList) {
		m.addAttribute("tables", tableList);
		return "report";
	}
}
